package com.csun.cmny.provider.controller;

import com.csun.cmny.core.annotation.ValidateAnnotation;
import com.csun.cmny.core.support.BaseController;
import com.csun.cmny.provider.model.dto.nursingRecords.NursingRecordsSaveDto;
import com.csun.cmny.provider.model.dto.nursingShiftChangeRecord.*;
import com.csun.cmny.provider.model.vo.nursingShiftChangeRecord.NursingShiftChangeRecordParticularsVo;
import com.csun.cmny.provider.model.vo.nursingShiftChangeRecord.NursingShiftChangeRecordVo;
import com.csun.cmny.provider.model.vo.nursingShiftChangeRecord.NursingShiftChangeVo;
import com.csun.cmny.provider.resolver.CmnyMessageSource;
import com.csun.cmny.provider.service.OmcNursingShiftChangeRecordService;
import com.csun.cmny.provider.service.OmcNursingShiftChangeService;
import com.csun.cmny.util.wrapper.WrapMapper;
import com.csun.cmny.util.wrapper.Wrapper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("/nursingShiftChangeRecord")
public class OmcNursingShiftChangeRecordController extends BaseController {

    @Resource
    private CmnyMessageSource cmnyMessageSource;

    @Resource
    private OmcNursingShiftChangeRecordService shiftChangeRecordService;

    @Resource
    private OmcNursingShiftChangeService changeService;


    @ValidateAnnotation
    @ApiOperation(httpMethod = "POST", value = "新增交班")
    @RequestMapping(value = "/addNursingShift", method = RequestMethod.POST)
    public Wrapper addNursingShiftChangeRecord(@RequestBody @Valid NursingShiftSaveDto shiftSaveDto, BindingResult br) {


        int result=shiftChangeRecordService.addNursingShift(shiftSaveDto,getLoginAuthDto());


        return WrapMapper.wrap(Wrapper.SUCCESS_CODE,cmnyMessageSource.getMessage("operation.success", null),result);
    }

    @ValidateAnnotation
    @ApiOperation(httpMethod = "POST", value = "新增接班")
    @RequestMapping(value = "/addNursingChange", method = RequestMethod.POST)
    public Wrapper addNursingChange(@RequestBody @Valid NursingChangeSaveDto changeSaveDto, BindingResult br) {


        int result=shiftChangeRecordService.addNursingChange(changeSaveDto,getLoginAuthDto());


        return WrapMapper.wrap(Wrapper.SUCCESS_CODE,cmnyMessageSource.getMessage("operation.success", null),result);
    }

    @ValidateAnnotation
    @ApiOperation(httpMethod = "POST", value = "查看本机构全部交接班记录")
    @RequestMapping(value = "/select", method = RequestMethod.POST)
    public Wrapper select(@RequestBody @Valid NursingShiftChangeSelectDto nursingShiftChangeSelectDto, BindingResult br) {

        List<NursingShiftChangeVo>list=changeService.selectShiftChangeRecord(nursingShiftChangeSelectDto);

        PageInfo<NursingShiftChangeVo> pageInfo = new PageInfo<>(list);

        return WrapMapper.wrap(Wrapper.SUCCESS_CODE,cmnyMessageSource.getMessage("operation.success", null),pageInfo);
    }

    @ValidateAnnotation
    @ApiOperation(httpMethod = "POST", value = "根据交接班记录id查询详情")
    @RequestMapping(value = "/selectNursingShiftChangeRecordById", method = RequestMethod.POST)
    public Wrapper selectNursingShiftChangeRecordById(Long id) {


        List<NursingShiftChangeRecordParticularsVo> nursingShiftChangeRecordParticularsVo=shiftChangeRecordService.selectNursingShiftChangeRecordById(id);


        return WrapMapper.wrap(Wrapper.SUCCESS_CODE,cmnyMessageSource.getMessage("operation.success", null),nursingShiftChangeRecordParticularsVo);
    }
}
